var mongoose = require("mongoose");
mongoose.connect('mongodb://localhost/test'); 

var db = mongoose.connection;
db.once('open', function(err){
    console.log("数据库成功打开！");
});

var animalSchema = new mongoose.Schema({
    "name": String,
    "type": String
});
animalSchema.methods.FindSametype = function(callback){     // 找同类[实例方法]
    this.model('Animal').find({"type":this.type},callback);
}
var Animal = mongoose.model('Animal',animalSchema);
// Animal.create({"name": "楼楼","type": "猫",});
// Animal.create({"name": "小白","type": "狗",});
// Animal.create({"name": "叮当","type": "猫",});
// Animal.create({"name": "二哈","type": "狗",});

Animal.findOne({"name":"小白"},function(err,result){
    var dog = result;
    dog.FindSametype(function(err,result){
        console.log(result);
    })
})